import { CreateUserDto, UpdateUserDto } from '@ai/entity';
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
import { Public } from '@/utils/metadata/public';
import { UserService } from './user.service';

@Controller('user')
export class UserController {
    constructor(private readonly userService: UserService) {}

    @Public()
    @Post()
    async create(@Body() createUserDto: CreateUserDto) {
        return await this.userService.create(createUserDto);
    }

    @Get()
    async findOneById(@Body('userId') userId: string) {
        return await this.userService.findOneById(userId);
    }

    // TODO: 权限校验
    @Get('list')
    async findList() {
        return await this.userService.findAll();
    }

    // TODO: 权限校验
    @Get(':id')
    findUserById(@Param('id') id: string) {
        return this.userService.findOneById(id);
    }

    @Patch('')
    async updateUser(@Body('userId') userId: string, @Body() updateUserDto: UpdateUserDto) {
        return await this.userService.findByIdAndUpdate(userId, updateUserDto);
    }

    // TODO: 权限校验
    @Patch(':id')
    async update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
        return this.userService.findByIdAndUpdate(id, updateUserDto);
    }

    // TODO: 权限校验
    @Delete(':id')
    remove(@Param('id') id: string) {
        console.log(`🚀 ~ file: user.controller.ts:47 ~ UserController ~ remove ~ id:`, id);
        return this.userService.deleteById(id);
    }
}
